<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<link rel="stylesheet" media="screen" href="css/docs.css"/>
<link rel="stylesheet" media="screen" href="lib/jqplot/jquery.jqplot.min.css"/>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>

<script type="text/javascript" src="${ctx}/js/global_util.js"></script>

<h1 class="page-title">外出申请单 - 添加</h1>

<div class="container_12 clearfix leading">
    <h5>流水号：<strong id="administration_serial_number"> </strong></h5>

    <div class="side grid_12 leading">
        <form class="form has-validation" name="post_form" id="post_form">
            <div class="clear"></div>
            <div class="clearfix">
                <label for="form_evectionReason" class="form-label">外出事由 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="form_evectionReason" name="applyForm.evectionReason" required="required" placeholder=""/>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="form_phone" class="form-label">公出联系电话 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="form_phone" name="applyForm.phone"  required="required" placeholder=""/>
                </div>
            </div>

            <%--<div class="clear"></div>
            <div class="clearfix">
                <label for="form_stay" class="form-label">预估往返时间 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="form_stay" name="applyForm.stay" required="required" placeholder=""/>
                </div>
            </div>--%>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="s_start_date" class="form-label">开始时间 <em>*</em></label>
                <div class="form-input">
                    <input type="text" class="date" id="s_start_date" name="s_start_date" onfocus="WdatePicker({maxDate:$('#s_end_date').val(), dateFmt:'yyyy-MM-dd HH:mm'})" readonly="readonly" value='<s:date name="#request.applyForm.startDate" format="yyyy-MM-dd"/>'/>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="s_end_date" class="form-label">结束时间 <em>*</em></label>
                <div class="form-input">
                    <input type="text" class="date" id="s_end_date" name="s_end_date" onfocus="WdatePicker({minDate:$('#s_start_date').val(), dateFmt:'yyyy-MM-dd HH:mm'})" readonly="readonly" value='<s:date name="#request.applyForm.endDate" format="yyyy-MM-dd"/>'/>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="form_customName" class="form-label">客户名称 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="form_customName" name="applyForm.customName" required="required" placeholder=""/>
                </div>
            </div>
            <div class="clear"></div>
            <div class="clearfix">
                <label for="form_customAddress" class="form-label">客户地址 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="form_customAddress" name="applyForm.customAddress" required="required" placeholder=""/>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="form_note" class="form-label">备 注 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="form_note" name="applyForm.note" required="required" placeholder=""/>
                </div>
            </div>

            <input type="hidden" name="applyForm.serialNumber" id="form_serialNumber">
            <div class="form-action clearfix">
                <button class="button" type="button" onclick="checkForm()">添加</button>
                <button class="button" type="reset">重置</button>
                <a class="button" href="#${userType==1?"sign" : "public"}/administration-out-apply-form.xhtml"> <span style="background:url(${ctx}/images/img/arrow_undo.png)" class="icon">&nbsp;</span>返回</a>
            </div>
        </form>
    </div>
</div>

<div class="clear"></div>

<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript">
    $(function(){
        var serial = createSerialNumber();
        $("#administration_serial_number").html(serial);
        $("#form_serialNumber").val(serial);
    });

    function checkForm(){
        var form_evectionReason = $("#form_evectionReason").val();
        if(checkNull(form_evectionReason)){
            alert("请填写外出事由");
            return;
        }
        var form_phone = $("#form_phone").val();
        if(checkNull(form_phone)){
            alert("请填写公出联系电话");
            return;
        }
        /*var form_stay = $("#form_stay").val();
        if(checkNull(form_stay)){
            alert("请填写预估往返时间");
            return;
        }*/
        var a_evectionStartDate = $("#s_start_date").val();
        if (checkNull(a_evectionStartDate)) {
            alert("请填写外出开始时间");
            return;
        }
        var a_evectionEndDate = $("#s_end_date").val();
        if (checkNull(a_evectionEndDate)) {
            alert("请填写外出结束时间");
            return;
        }
        var form_customName = $("#form_customName").val();
        if(checkNull(form_customName)){
            alert("请填写客户名称");
            return;
        }
        var form_customAddress = $("#form_customAddress").val();
        if(checkNull(form_customAddress)){
            alert("请填写客户地址");
            return;
        }
        var form_note = $("#form_note").val();
        if(checkNull(form_note)){
            alert("请填写备注");
            return;
        }

        var data  = $("#post_form").serialize();
        var url = "${ctx}/${userType==1?"sign" : "public"}/administration-out-apply-form-save.xhtml";
        $.ajax(url, {
            type: "POST",
            data: data,
            dataType:"html",
            cache:false,
            success:function(a) {
                return pageDownloaded(a, url)
            },
            complete:function() {}
        });
    }
</script>